Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplification pass #256

Merged
merged 157 commits into from
Feb 13, 2025
Merged

Simplification pass #256

merged 157 commits into from
Feb 13, 2025

Conversation

ailrst
Copy link
Contributor

@ailrst ailrst commented Oct 9, 2024

Adds the flag --simplify (which implies --parameter-form) which, after running analysis performs partial evaluation and simplification of the IR.

This usually removes the flag registers and pushes the comparisons into the assume statements where they are used, folds constants through and does some canonicalisation and term simplification.

It sits on top of the interpreter #241 for partial evaluation, and includes improvements to the parameter form which I will copy into that PR #255. When #243 is merged we should use the interpreter to validate the transform using the memory state hash the csmith examples produce. Currently this is just validated against the system tests, all of which pass with the transform applied.

this implements:

  • lift registers to locals and pass everything via procedure parameters (this required adding parameters to the IR)
  • a dynamic single assignment transform via variable renaming, adds an index field to local variables for this purpose so we can easily rename them without
  • constant + copy propagation over the IR
  • multiple term-rewriting based simplification passes
  • a pass to convert 64 bit locals where only the low n bits are accessed to variables of n bits

The simplification/partial eval/copyprop rewrites are applied repeatedly with a fixed number of iterations.

For an example of what simplifications this produces: https://gist.github.com/ailrst/1b29e85a6ad891810dcc83801b1e2c6a

ailrst and others added 17 commits January 24, 2025 12:14
* preorder iterator

* add pass to inline invariant proc params

* autofmt

* add test for mem reasoning

* print boogie code failing verification

* only inline dont remove outparam for spec

* single-pass variable indexing analysis to replace IntraSSA

* remove ssa analysis

* disable R30_out=R30_in assertion on main procedure

Main will often maintain the stack by loading R30 from its caller's stack frame
before returning, which makes the R30 assertion fail.

Instead of disabling the assertion, in the future we should
add a precondition for the stack layout before main but the
interaction between spec and static analysis is no implemented yet.

* fix bug in outparam inlining, still breaks dsa form

* outparam inlining maintain dsa

* iterate outparam inlining

* convert indirectcall to call to trampoline

* pprint assert comments

* recognise linux __assert_fail

* recognise svcomp structures

* fix inlining dsa invariant

* interproc frame analysis

---------

Co-authored-by: l-kent <[email protected]>
Co-authored-by: l-kent <[email protected]>
* Lattice sets and maps

* Product domains and disjunctive completions

* Fix lattice map joins on bottom

* Move bounding a disjunctive completion to a seperate method

* Explain disjunctive completions
* support new lifter error format

* more debugging asserts

* fix cilvisitor repeatbits

* keep going on lift failure

* escape dotgraph label
@utting
Copy link
Contributor

utting commented Feb 10, 2025

It would be nice to have some top-level comments (e.g. on class SimpExpr) to give an overview of how simplification works and what transforms the 'simplifier' argument can do. Should this be listed as an extra translation phase in docs/readme.md?

@ailrst
Copy link
Contributor Author

ailrst commented Feb 11, 2025

I've added some docs here, mainly api docs on simplifyExpr and AbsInt and the simplification pass summary to the markdown. #318.

@ailrst ailrst force-pushed the simplification-pass branch from cf09f7b to 5c4df37 Compare February 12, 2025 04:30
@utting utting self-requested a review February 13, 2025 03:58
Copy link
Contributor

@utting utting left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.
Lots of enhancements, including interpreters, simplifiers, parameter inference etc.
Some of the docs should be updated (e.g. update interpreter.md to mention where more intrinsics are implemented) and some of the monad definitions might benefit from more docs or references so new programmers can understand the concepts.
But these can be updated after merge.

@utting utting merged commit d0745de into main Feb 13, 2025
4 checks passed
@utting
Copy link
Contributor

utting commented Feb 13, 2025

Merged simplification pass into main, before adding the scalafmt changes, to give a clearer history of the merge.

@ailrst ailrst mentioned this pull request Feb 14, 2025
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants